// pages/mycurriculum/mycurriculum.js
var app = getApp(), api = app.api;
var is_more = !1;
var app = getApp(), api = getApp().api, is_no_more = !1, is_loading = !1, p = 2;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    course_date_list:[],
    list:[],
    open:0,
    course_date:'',
    month:"",
    day:"",


    page:1,
    course_date_list:[],
    list:[],
    open:0,
    course_date:0,


    is_teacher:[],

    show: !1,
    status: -1,
    mch:[],
    order_list: [],
    show_no_data_tip: !1,
    hide: 1,
    qrcode: "",
    revoke_tpl: '',
    share_modal_active:''
  },
  // list:function(res){
  //   console.log(res)
  //   console.log(res,'id')
  //   var id=res.currentTarget.dataset.goods_id;
  //   wx.navigateTo({
  //     url: '/pages/my-class-teacher-list/my-class-teacher-list?goods_id=' + id,
  //   })
  // },
list:function(res){
  console.log(res)
  console.log(res)
  var id=res.currentTarget.dataset.mch_id;
  wx.navigateTo({
    url: '/pages/my-class-user-list/my-class-user-list?mch_id=' + id,
  })
},
  bindDateChange: function(e) {
    var aa = e.detail.value.split('-')
    console.log(aa)
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      month:aa[1],
      day:aa[2]
    })},






  loadOrderList: function(t) {
    null == t && (t = -1);
    var e = this;
    e.setData({
        status: t
    }), getApp().core.showLoading({
        title: "正在加载",
        mask: !0
    });
    var a = {
        status: e.data.status
    }; 
    e.data.options;
    void 0 !== e.data.options.order_id && (a.order_id = e.data.options.order_id), getApp().request({
        url: getApp().api.order.list,
        data: a,
        success: function(t) {
            console.log(t.data.list);
            0 == t.code && (e.setData({
                mch:t.data.list.mch,
                order_list: t.data.list,
                pay_type_list: t.data.pay_type_list,
                revoke_tpl: t.data.revoke_tpl
            }), getApp().core.getStorageSync(getApp().const.ITEM) && getApp().core.removeStorageSync(getApp().const.ITEM));
            e.setData({
                show_no_data_tip: 0 == e.data.order_list.length
            });
        },
        complete: function() {
            getApp().core.hideLoading();
        }
    });
},


  getData: function() {
    var e = this;
    getApp().core.showLoading({
        title: "加载中"
    }), getApp().request({
        url: getApp().api.recharge.record,
        data: {
            date: e.data.date_1 || ""
        },
        success: function(t) {
          console.log(t,'tttttttttttt11111111111')
            e.setData({
                list: t.data.list
            }), getApp().core.hideLoading(), is_more = !1;
        }
    });
},


  dateChange: function(t) {
    if (!is_more) {
        is_more = !0;
        var e = t.detail.value, a = e.replace("-", "年") + "月";
        this.setData({
            date: a,
            date_1: e
        }), this.getData();
    }
},
dateUp: function() {
  var t = this;
  if (!is_more) {
      is_more = !0;
      var e = t.data.date_1, a = (t.data.date, new Date(e));
      a.setMonth(a.getMonth() + 1);
      var o = a.getMonth() + 1;
      o = (o = o.toString())[1] ? o : "0" + o, t.setData({
          date: a.getFullYear() + "年" + o + "月",
          date_1: a.getFullYear() + "-" + o
      }), t.getData();
  }
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
   
    var that = this
    that.class_list()
    that.teacher_class()
 
    getApp().core.getStorage({
        key: "USER_INFO",
        success: function(a) {
          console.log(a.data.is_teacher)
            // t.setData({
            //     is_teacher:a.data.is_teacher
            // });
            if(a.data.is_teacher == 1){
              that.teacher_class()
  
            }else{
            
              that.class_list()
            }
        }
    })


    getApp().page.onLoad(this, t);
    var e = this
    e.class_list()
    
    e.setData({
      user_id: getApp().core.getStorageSync("USER_INFO").id,
  }),
  is_loading = is_no_more = !1, p = 2, e.setData({
      options: t
  }), e.loadOrderList(t.status || -1), getCurrentPages().length < 2 && e.setData({
      show_index: !0
  });


   

  },
  	//點擊簽到簽退
    qian_button(e,type,index,indexs) {
      console.log(e,'eeeeeeeeeeeee')
      var that = this
      var type = e.currentTarget.dataset.type
      var index = e.currentTarget.dataset.index
      var indexs = e.currentTarget.dataset.indexs
      getApp().request({
              url: getApp().api.schoolclass.student_sign,
              method: "GET",
              data: {
                  course_time_id:e.currentTarget.dataset.course_time_id,
                  type: type
              },
              success: function (res) {
                  console.log(res, 'resresres')
                  if (res.code ==0) {
                    var cou_arr = that.data.list
                    console.log(cou_arr);
                    console.log(index);
                    console.log(indexs);
                    if(type == 1){
                      
                      cou_arr[index].class_course_time[indexs].course_sign_out_time = res.sign_time
                    }else{
                      cou_arr[index].class_course_time[indexs].course_sign_in_time = res.sign_time
                    }
                    that.setData({
                        list:cou_arr
                    })
                  }
              
                  wx.showToast({
                    title: res.msg,
                    icon:'none'
                  })
                  // that.setData({
                  //   page:0,
                  //   list:[]
                  // })
                  // that.class_list()
              }
            });
    },
    //点击签到签退
get_myclass:function(e){
  console.log('e',e)
  wx.navigateTo({ url: '/schoolclass/collegeSign/index?course_time_id='+e.currentTarget.dataset.course_time_id+'&sign_type='+e.currentTarget.dataset.sign_type, })
},
  class_list:function(e){
    
    console.log(e,'e')
 
    console.log(that,'thatclass')
    var that = this
    getApp().request({
            url: getApp().api.schoolclass.myclass,
            method: "GET",
            data: {
                page:that.data.page,
                course_date:that.data.course_date
            },
            success: function (res) {
             console.log(res, '数据class')//接口添加一个月份的字段 
              that.setData({
                course_date_list:res.data.course_date_list,
            })
              for(var i =0;i<res.data.list.length;i++){
                that.data.list.push(res.data.list[i])
                that.setData({
                  list : that.data.list
              })
              }
            }
          });
  },
  teacher_class:function(){
    var that = this;
    console.log(that,'teacherthat')
    getApp().request({
            url: getApp().api.schoolclass.class_list,
            method: "GET",
            data: {
                page:that.__data__.page,
                course_date:that.__data__.course_date
            },
            success: function (res) {
               console.log(res.data.list, '数据teacher')
                that.setData({
                  course_date_list:res.data.course_date_list
              })
              for(var i =0;i<res.data.list.length;i++){
                that.data.list.push(res.data.list[i])
                that.setData({
                  list : that.data.list
              })
             }
            }
          });
  },
// 点击选中日期
open_time:function(e){
  var that = this
  console.log('e:',e)
  that.setData({
    open:e.currentTarget.dataset.index,
    course_date:e.currentTarget.dataset.course_date,
    page:0,
    list:[]
  })
  that.class_list()
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    getApp().page.onReady(this);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    getApp().page.onShow(this);

  




    // var e = this;
    // getApp().core.showLoading({
    //     title: "加载中"
    // });
    // var a = getApp().core.getStorageSync(getApp().const.USER_INFO);
    // getApp().request({
    //     url: getApp().api.recharge.index,
    //     success: function(t) {
    //         a.money = t.data.money, getApp().core.setStorageSync(getApp().const.USER_INFO, a), 
    //         e.setData({
    //             user_info: a,
    //             list: t.data.list,
    //             setting: t.data.setting,
    //             date_1: t.data.date,
    //             date: t.data.date.replace("-", "年") + "月"
    //         }), getApp().core.hideLoading();
    //     }
    // });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    getApp().page.onHide(this);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    getApp().page.onUnload(this);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    that.setData({
      page:that.data.page + 1
    })
    that.class_list()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  get_baoming: function () {
    wx.switchTab({
      url: '/pages/cat/cat',
    })
  }
})